package com.tang.framework.core.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tang.common.enums.UserStatus;

import com.tang.framework.component.security.model.PermissionAuthority;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author tang jun liang
 * @Date 2023/2/10 13:51
 */
@Data
@Schema
public class LoginUser implements UserDetails {

    @Schema(description = "权限列表")
    private List<PermissionAuthority> authorities;


    @Schema(description = "菜单")
    private List<String> menuList;

    @JsonIgnore
    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return userStatus.equals(UserStatus.ENABLE);
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return userStatus.equals(UserStatus.ENABLE);
    }


    @JsonIgnore
    @Schema(description = "密码")
    private String password;


    @Schema(description = "登录密码")
    private String loginPassword;


    @Schema(description = "用户id")
    private Long userId;

    @Schema(description = "用户名")
    private String username;

    @Schema(description = "手机号")
    private String phone;


    @Schema(description = "租户id")
    private String tenantId;


    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "token过期时间")
    private LocalDateTime expireTime;


    @Schema(description = "token")
    private String token;


    @Schema(description = "用户状态")
    private UserStatus userStatus;


    @Schema(description = "数据库名称")
    private String databaseName;

    @Schema(description = "用户权限")
    private Boolean userDataAuthor;

    @Schema(description = "部门权限")
    private Boolean deptDataAuthor;

    @Schema(description = "租户权限")
    private Boolean tenantDataAuthor;

    @Schema(description = "授权部门id列表")
    private List<Long> endowDeptIdList;

    @Schema(description = "授权用户id列表")
    private List<Long> endowUserIdList;

    @Schema(description = "部门id")
    private Long deptId;



}
